const path = require('path')

const { spawn } = require('child_process')

const conf = {
    path: path.resolve(__dirname, './test.jpg'),
    k: 2, // k >= 2
    min_px: 100,
    color_thresh: 20
}

const process = spawn('python', ['split.py', JSON.stringify(conf)], {
    windowsHide: true,
    encoding: 'utf-8',
})

process.stdout.on('data', data => {
    const decoded = data.toString('utf-8').trim()
    // console.log('输出:', decoded)
})

process.stderr.on('data', data => {
    const decoded = data.toString('utf-8').trim()
    console.error(decoded)
})

process.on('close', code => {
    console.log(`子进程退出，代码: ${code}`);
})